<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>0</h1>
<input type="button" value="停止" onclick="f1()">
<script>
  let count=0;
  let h=document.querySelector("h1");
  //setInterval(f,1000);
  let timer=setInterval(function (){
    h.innerText=count++;
  },1000)

  function f1() {
    clearTimeout(timer);
  }
  function f(){
    count++;
    let h=document.querySelector("h1");
   h.innerText=count;
  }
  setTimeout(function (){
    console.log("时间到")
  },5000)
</script>
</body>
</html>